<template>
	<view class="content">
		<view style="height: 187rpx;"></view>
		<view class="textCen fowe800" style="font-size: 60rpx;color: #C38D5F;">登录</view>
		<button @getphonenumber="getWechatMobile" open-type="getPhoneNumber" 
			class="wx mar hei80 dis disAl disJuC coFFF foSi30 borRad40 mar-top30">一键登录</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				phone: ''
			}
		},
		onLoad() {
		},
		methods: {
			getWechatMobile(e) {
				var that = this;
				if (e.detail.errMsg != 'getPhoneNumber:ok') {
					return false;
				}
				uni.showLoading({
					title: '登录中'
				});
				console.log(e.detail.code)
				// return
				uni.request({
					url: that.global.url + 'api/qianyu_petrol/gasstation_userlogin', 
					method: 'GET', 
					header: {
						'site-id': that.global.site_id,
					}, 
					data: {
						code: e.detail.code,
						openid: uni.getStorageSync('openid'),
						parent_id : uni.getStorageSync('parent_id')
					}, 
					complete: function () {
						uni.hideLoading();
					}, 
					success: function (result) {
						var apiResult = result.data;
						uni.showToast({
							title: apiResult.msg,
							icon: 'none',
							duration: 1000
						});
						if (apiResult.code == 1) {
							uni.setStorageSync('userinfo', apiResult.data);
							uni.setStorageSync('token', apiResult.data.token);
							setTimeout(function () {
								uni.switchTab({
									url: '/pages/index/index'
								});
							}, 1000);
						}
					}
				});
			},
		}
	}
</script>

<style>
	.content {
		height: 100vh;
		background-color: #F4EDDD;
	}

	.wx {
		background-color: #009B4C;
		width: 450rpx;
	}
</style>